package com.syys.privacy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.syys.common.annotation.Log;
import com.syys.common.enums.BusinessType;
import com.syys.privacy.domain.QaAnswer;
import com.syys.privacy.service.IQaAnswerService;
import com.syys.common.core.controller.BaseController;
import com.syys.common.core.domain.AjaxResult;
import com.syys.common.utils.poi.ExcelUtil;
import com.syys.common.core.page.TableDataInfo;

/**
 * 问题答案Controller
 *
 * @author ys
 * @date 2021-07-15
 */
@Controller
@RequestMapping("/privacy/answer")
public class QaAnswerController extends BaseController {
    private String prefix = "privacy/answer";

    @Autowired
    private IQaAnswerService qaAnswerService;

//    @RequiresPermissions("privacy:answer:view")
    @GetMapping()
    public String answer() {
        return prefix + "/answer";
    }

    /**
     * 查询问题答案列表
     */
//    @RequiresPermissions("privacy:answer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QaAnswer qaAnswer) {
        startPage();
        List<QaAnswer> list = qaAnswerService.selectQaAnswerList(qaAnswer);
        return getDataTable(list);
    }

    /**
     * 导出问题答案列表
     */
//    @RequiresPermissions("privacy:answer:export")
    @Log(title = "问题答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QaAnswer qaAnswer) {
        List<QaAnswer> list = qaAnswerService.selectQaAnswerList(qaAnswer);
        ExcelUtil<QaAnswer> util = new ExcelUtil<QaAnswer>(QaAnswer.class);
        return util.exportExcel(list, "问题答案数据");
    }

    /**
     * 新增问题答案
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存问题答案
     */
//    @RequiresPermissions("privacy:answer:add")
    @Log(title = "问题答案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QaAnswer qaAnswer) {
        return toAjax(qaAnswerService.insertQaAnswer(qaAnswer));
    }

    /**
     * 修改问题答案
     */
    @GetMapping("/edit/{answerId}")
    public String edit(@PathVariable("answerId") Long answerId, ModelMap mmap) {
        QaAnswer qaAnswer = qaAnswerService.selectQaAnswerById(answerId);
        mmap.put("qaAnswer", qaAnswer);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题答案
     */
//    @RequiresPermissions("privacy:answer:edit")
    @Log(title = "问题答案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QaAnswer qaAnswer) {
        return toAjax(qaAnswerService.updateQaAnswer(qaAnswer));
    }

    /**
     * 删除问题答案
     */
//    @RequiresPermissions("privacy:answer:remove")
    @Log(title = "问题答案", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(qaAnswerService.deleteQaAnswerByIds(ids));
    }
}
